package com.codequirks.xmlbeanutils;

import org.w3c.dom.Attr;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 * Default implementation of the {@link NodePropertyAccessor} used by {@link XmlDynaBean}
 * if none is provided.
 *
 * @author Travis Calder <travis.calder@gmail.com>
 * @since 1.0.1
 */
public class DefaultNodePropertyAccessor implements NodePropertyAccessor {
    @Override
    public NodeList getAllChildren(Node node) {
        return node.getChildNodes();
    }

    @Override
    public NamedNodeMap getAllAttributes(Node node) {
        return node.getAttributes();
    }

    @Override
    public String getNodeName(Node node) {
        return node.getNodeName();
    }

    @Override
    public String getAttributeContents(Attr attribute) {
        return attribute.getTextContent();
    }

    @Override
    public String getNodeText(Node node) {
        return node.getTextContent();
    }
}
